package com.webchat.model;

import org.json.JSONObject;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.HashMap;

/**
 * Created by YongX on 2016/8/20.
 */
@Entity
@Table(name = "users", schema = "meshop", catalog = "")
public class UsersEntity {
    private int id;
    private String name;
    private String signature;
    private String email;
    private String password;
    private String headimg;
    private String phone;
    private byte isAdmin;
    private byte isAssent;
    private byte isActive;
    private int adminLevel;
    private int userLevel;
    private String onlineTime;
    private String rememberToken;
    private String chatToken;
    private Timestamp createdAt;
    private Timestamp updatedAt;

    @Id
    @Column(name = "id")
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "signature")
    public String getSignature() {
        return signature;
    }

    public void setSignature(String signature) {
        this.signature = signature;
    }

    @Basic
    @Column(name = "email")
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Basic
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "headimg")
    public String getHeadimg() {
        return headimg;
    }

    public void setHeadimg(String headimg) {
        this.headimg = headimg;
    }

    @Basic
    @Column(name = "phone")
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "is_admin")
    public byte getIsAdmin() {
        return isAdmin;
    }

    public void setIsAdmin(byte isAdmin) {
        this.isAdmin = isAdmin;
    }

    @Basic
    @Column(name = "is_assent")
    public byte getIsAssent() {
        return isAssent;
    }

    public void setIsAssent(byte isAssent) {
        this.isAssent = isAssent;
    }

    @Basic
    @Column(name = "is_active")
    public byte getIsActive() {
        return isActive;
    }

    public void setIsActive(byte isActive) {
        this.isActive = isActive;
    }

    @Basic
    @Column(name = "admin_level")
    public int getAdminLevel() {
        return adminLevel;
    }

    public void setAdminLevel(int adminLevel) {
        this.adminLevel = adminLevel;
    }

    @Basic
    @Column(name = "user_level")
    public int getUserLevel() {
        return userLevel;
    }

    public void setUserLevel(int userLevel) {
        this.userLevel = userLevel;
    }

    @Basic
    @Column(name = "online_time")
    public String getOnlineTime() {
        return onlineTime;
    }

    public void setOnlineTime(String onlineTime) {
        this.onlineTime = onlineTime;
    }

    @Basic
    @Column(name = "remember_token")
    public String getRememberToken() {
        return rememberToken;
    }

    public void setRememberToken(String rememberToken) {
        this.rememberToken = rememberToken;
    }

    @Basic
    @Column(name = "chat_token")
    public String getChatToken() {
        return chatToken;
    }

    public void setChatToken(String chatToken) {
        this.chatToken = chatToken;
    }

    @Basic
    @Column(name = "created_at")
    public Timestamp getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Timestamp createdAt) {
        this.createdAt = createdAt;
    }

    @Basic
    @Column(name = "updated_at")
    public Timestamp getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Timestamp updatedAt) {
        this.updatedAt = updatedAt;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        UsersEntity that = (UsersEntity) o;

        if (id != that.id) return false;
        if (isAdmin != that.isAdmin) return false;
        if (isAssent != that.isAssent) return false;
        if (isActive != that.isActive) return false;
        if (adminLevel != that.adminLevel) return false;
        if (userLevel != that.userLevel) return false;
        if (name != null ? !name.equals(that.name) : that.name != null) return false;
        if (signature != null ? !signature.equals(that.signature) : that.signature != null) return false;
        if (email != null ? !email.equals(that.email) : that.email != null) return false;
        if (password != null ? !password.equals(that.password) : that.password != null) return false;
        if (headimg != null ? !headimg.equals(that.headimg) : that.headimg != null) return false;
        if (phone != null ? !phone.equals(that.phone) : that.phone != null) return false;
        if (onlineTime != null ? !onlineTime.equals(that.onlineTime) : that.onlineTime != null) return false;
        if (rememberToken != null ? !rememberToken.equals(that.rememberToken) : that.rememberToken != null)
            return false;
        if (chatToken != null ? !chatToken.equals(that.chatToken) : that.chatToken != null) return false;
        if (createdAt != null ? !createdAt.equals(that.createdAt) : that.createdAt != null) return false;
        if (updatedAt != null ? !updatedAt.equals(that.updatedAt) : that.updatedAt != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (signature != null ? signature.hashCode() : 0);
        result = 31 * result + (email != null ? email.hashCode() : 0);
        result = 31 * result + (password != null ? password.hashCode() : 0);
        result = 31 * result + (headimg != null ? headimg.hashCode() : 0);
        result = 31 * result + (phone != null ? phone.hashCode() : 0);
        result = 31 * result + (int) isAdmin;
        result = 31 * result + (int) isAssent;
        result = 31 * result + (int) isActive;
        result = 31 * result + adminLevel;
        result = 31 * result + userLevel;
        result = 31 * result + (onlineTime != null ? onlineTime.hashCode() : 0);
        result = 31 * result + (rememberToken != null ? rememberToken.hashCode() : 0);
        result = 31 * result + (chatToken != null ? chatToken.hashCode() : 0);
        result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0);
        result = 31 * result + (updatedAt != null ? updatedAt.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "UsersEntity{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", signature='" + signature + '\'' +
                ", email='" + email + '\'' +
                ", password='" + password + '\'' +
                ", headimg='" + headimg + '\'' +
                ", phone='" + phone + '\'' +
                ", isAdmin=" + isAdmin +
                ", isAssent=" + isAssent +
                ", isActive=" + isActive +
                ", adminLevel=" + adminLevel +
                ", userLevel=" + userLevel +
                ", onlineTime='" + onlineTime + '\'' +
                ", rememberToken='" + rememberToken + '\'' +
                ", chatToken='" + chatToken + '\'' +
                ", createdAt=" + createdAt +
                ", updatedAt=" + updatedAt +
                '}';
    }


    public String userBasicAttributes(){
        HashMap<String, String> map = new HashMap<String, String>();
        map.put("id", this.getId()+"");
        map.put("name", this.getName());
        map.put("headimg", this.getHeadimg());
        map.put("time", this.getOnlineTime());
        JSONObject jsonObject = new JSONObject(map);
        return  jsonObject.toString();
    }
}
